/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "NewTon刚体.h"


#include <dNewtonDynamicBody.h>
#include <矩阵.h>


//auto my_ground = chrono::ChBodyEasyBox(60, 2, 60, 1.0, true, true);

S_NewTon刚体::S_NewTon刚体(S_NewTon核心* core, S_物理几何体& geom, S_物理材质& 材质, uint32 key) {
	//m_物理引擎枚举 = E_物理引擎::E_物理引擎_NewTon;
	m_Type = E_物理体类型::E_物理体_刚体;

	switch (geom.m_Type) {
	case E_物理碰撞几何类型::E_碰撞几何_方体:
		{
			
		}
		break;
	case E_物理碰撞几何类型::E_碰撞几何_凸壳:
		{
			
		}
		//m_刚体 = chrono::ChBodyEasyConvexHull(g->m_Points, g->m_密度);
		break;
	default:
		break;
	}

	Mat44f mat;
	f_构建单位矩阵(&mat);
	m_刚体 = NewtonCreateDynamicBody(core->m_物理世界, (NewtonCollision*)geom.f_get几何体物理对象(), (float32*)&mat);
	//auto a = new chrono::ChBodyEasyBox(60, 2, 60, 1.0, true, true);
	//m_刚体 = chrono::ChBodyEasyConvexHull();
	//m_刚体.AddMarker();
	//CreateRigidBody()
	NewtonBodySetMassMatrix(m_刚体, -9.8f, 1, 1, 1);
	//NewtonBodySetSleepState(m_刚体, 2);
	//NewtonBodySetSimulationState(m_刚体, 2);
	NewtonBodySetLinearDamping(m_刚体, 0.0);
	//NewtonBodySetAngularDamping(m_刚体, 0.0);
	float32 a[3] = { 0.0, 0.0, 0.0 };
	NewtonBodySetTorque(m_刚体, a);
}

S_NewTon刚体::~S_NewTon刚体() {
	NewtonDestroyBody(m_刚体);
}

void S_NewTon刚体::f_setLocRot(const vec3& loc, const vec3& r) {
	Mat44f mat;
	f_构建移动矩阵(&mat, loc.x, loc.y, loc.z);
	NewtonBodySetMatrix(m_刚体, (const float32*)&mat);
	//NewtonBodySetOmega(m_刚体, (const float32*)&loc);
}

void S_NewTon刚体::f_setPos(const vec3& l)
{
}

void S_NewTon刚体::f_setRot(const vec3& r)
{
}

void S_NewTon刚体::f_setVel(const vec3& l)
{
}

vec3 S_NewTon刚体::f_getLocation()
{
	return vec3();
}

S_NewTon静态::S_NewTon静态(S_NewTon核心* core, S_物理几何体& geom, S_物理材质& 材质, uint32 key) {
	//m_物理引擎枚举 = E_物理引擎::E_物理引擎_NewTon;
	m_Type = E_物理体类型::E_物理体_静态;

	switch (geom.m_Type) {
	case E_物理碰撞几何类型::E_碰撞几何_方体:
	{

	}
	break;
	case E_物理碰撞几何类型::E_碰撞几何_凸壳:
	{

	}
	//m_刚体 = chrono::ChBodyEasyConvexHull(g->m_Points, g->m_密度);
	break;
	default:
		break;
	}

	Mat44f mat;
	f_构建单位矩阵(&mat);
	m_刚体 = NewtonCreateDynamicBody(core->m_物理世界, (NewtonCollision*)geom.f_get几何体物理对象(), (float32*)&mat);
	//m_刚体 = NewtonCreateKinematicBody(core->m_物理世界, (NewtonCollision*)geom.f_get几何体物理对象(), (float32*)&mat);
	
	//auto a = new chrono::ChBodyEasyBox(60, 2, 60, 1.0, true, true);
	//m_刚体 = chrono::ChBodyEasyConvexHull();
	//m_刚体.AddMarker();
	//CreateRigidBody()
	NewtonBodySetMassMatrix(m_刚体, -9.8f, 1, 1, 1);
	//NewtonBodySetSleepState(m_刚体, 2);
	//NewtonBodySetSimulationState(m_刚体, 2);
	NewtonBodySetLinearDamping(m_刚体, 0.0);
	//NewtonBodySetAngularDamping(m_刚体, 0.0);
	float32 a[3] = { 0.1, 0.1, 0.1 };
	NewtonBodySetTorque(m_刚体, a);
}

S_NewTon静态::~S_NewTon静态()
{
}

void S_NewTon静态::f_setLocRot(const vec3& loc, const vec3& r) {
	Mat44f mat;
	f_构建移动矩阵(&mat, loc.x, loc.y, loc.z);
	NewtonBodySetMatrix(m_刚体, (const float32*)&mat);
	//NewtonBodySetOmega(m_刚体, (const float32*)&loc);
}

void S_NewTon静态::f_setPos(const vec3& l)
{
}

void S_NewTon静态::f_setRot(const vec3& r)
{
}

void S_NewTon静态::f_setVel(const vec3& l)
{
}

vec3 S_NewTon静态::f_getLocation()
{
	return vec3();
}



